package com.atwei.mango.system.account.service.impl;

import com.atwei.mango.system.account.entity.Res;
import com.atwei.mango.system.account.mapper.ResMapper;
import com.atwei.mango.system.account.service.ResService;
import com.atwei.mango.system.account.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Classname ResService
 * @Description
 * @Date 2022/6/10 14:52
 * @Author liuwei
 */
@Service
public class ResServiceImpl implements ResService {

    @Autowired
    private RoleService roleService;

    @Resource
    private ResMapper resMapper;

    @Override
    public List<Res> getResByUserId(Integer accountId){
        //获取用户的角色
        List<Integer> rolesByAccountId = roleService.getRolesByAccountId(accountId);
        if (0 == rolesByAccountId.size()){
            return null;
        }
        List<Integer> resIds = roleService.getRessByRoleIds(rolesByAccountId);
        if (0 == resIds.size()){
            return null;
        }
        List<Res> res = resMapper.selectBatchIds(resIds);
        if (0 == res.size()){
            return null;
        }
        return res;
    }

}
